package com.wdy.service.impl;

import java.util.List;

import com.wdy.dao.FacilityDao;
import com.wdy.po.Facility;
import com.wdy.po.Page;
import com.wdy.po.Result;
import com.wdy.service.FacilityManager;
import com.wdy.util.PageUtil;

public class FacilityManagerImpl implements FacilityManager {

	private FacilityDao facilityDao;
	
	public void setFacilityDao(FacilityDao facilityDao) {
		this.facilityDao = facilityDao;
	}

	
	public void saveFacility(Facility facility) {
		facilityDao.save(facility);
	}

	
	public void removeFacility(Facility facility) {
		facilityDao.delete(facility);
	}

	
	public void updateFacility(Facility facility) {
		facilityDao.attachDirty(facility);
	}

	
	public Facility getFacility(Integer id) {
		return facilityDao.findById(id);
	}


	public List<Facility> listAll() {
		return facilityDao.findAll();
	}

	
	public List<Facility> findByExample(Facility facility) {
		return facilityDao.findByExample(facility);
	}


	public List<Facility> findByName(String value) {
		return facilityDao.findByFname(value);
	}

	public Result listFacility(Page page) {
		int totalRecords = this.facilityDao.getFacilityCount();
		page = PageUtil.createPage(page, totalRecords);
		List<Facility> facilitys = (List<Facility>)this.facilityDao.getFacilityByPage(page);     
		return new Result(page, facilitys);
	}

}
